package cn.tedu.course.employee.controller;

import cn.tedu.course.base.response.JsonResult;
import cn.tedu.course.employee.pojo.dto.EmployeeParam;
import cn.tedu.course.employee.pojo.dto.EmployeeQuery;
import cn.tedu.course.employee.pojo.vo.EmployeeVO;
import cn.tedu.course.employee.service.EmployeeService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @BelongsProject: course-jsd2503-student
 * @BelongsPackage: cn.tedu.course.employee.controller
 * @Author: yinwenkang
 * @CreateTime: 2025-06-14  10:07
 * @Description: TODO
 * @Version: 1.0
 */
@RestController
@RequestMapping("v1/employee")
@Slf4j
@Tag(name = "员工模块")
public class EmployeeController {
    @Autowired
    EmployeeService employeeService;

    /**
     * 查询员工
     *
     * @param employeeQuery
     * @return List<EmployeeVO>
     */
    @Operation(summary = "查询员工")
    @ApiOperationSupport(order = 10)
    @GetMapping("select")
    public JsonResult selectEmployee(EmployeeQuery employeeQuery) {
        log.debug("查询员工 employeeVO={}", employeeQuery);
        List<EmployeeVO> list = employeeService.selectEmp(employeeQuery);
        return JsonResult.ok(list);
    }

    /**
     * 更新员工状态
     *
     * @param id
     * @return
     */
    @Operation(summary = "更新员工状态")
    @ApiOperationSupport(order = 20)
    @PostMapping("update/{id}/{status}")
    public JsonResult updateStatus(@PathVariable Long id, @PathVariable String status) {
        log.debug("更新员工状态 id={} status={}", id, status);
        employeeService.updateStatus(id,status);
        return JsonResult.ok();
    }

    /**
     * 保存用户
     */
    @Operation(summary = "保存员工")
    @ApiOperationSupport(order = 30)
    @PostMapping("save")
    public JsonResult saveEmployee(@Validated EmployeeParam employeeParam){
        log.debug("保存员工：employeeParam={}",employeeParam);
        employeeService.saveEmp(employeeParam);
        return JsonResult.ok();
    }

}
